package cn.qayy.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletContext;

import cn.qayy.constants.CollectionConstant;
import cn.qayy.constants.Constant;
import cn.qayy.service.Uploadable;
import cn.qayy.utils.ServletContextUtils;
import cn.qayy.utils.StringUtil;

/**
 * 
 * 
 * @author wangyu
 * 
 * @date 2018-09-03
 */
public class PrizeDTO extends commonDTO implements Serializable,Uploadable{
    /**
     * 奖品名称
     */
    private String prizeName;

    /**
     * 发货日期
     */
    private String deliveryTime;

    /**
     * 发货状态
     */
    private String deliveryStatus;

    /**
     * 发货人
     */
    private String deliveryMan;

    /**
     * 收货人
     */
    private String consignee;

    /**
     * 收货地址
     */
    private String address;
    
    private String flag;
    
    private String openid;
    
    /**
	 * 修订标识
	 */
	private String isUpdate = "E";
	
	private String id;
	
	
	
	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public String getPrizeName() {
		return prizeName;
	}

	public void setPrizeName(String prizeName) {
		this.prizeName = prizeName;
	}

	public String getDeliveryTime() {
		return deliveryTime;
	}

	public void setDeliveryTime(String deliveryTime) {
		this.deliveryTime = deliveryTime;
	}

	public String getDeliveryStatus() {
		return deliveryStatus;
	}

	public void setDeliveryStatus(String deliveryStatus) {
		this.deliveryStatus = deliveryStatus;
	}

	public String getDeliveryMan() {
		return deliveryMan;
	}

	public void setDeliveryMan(String deliveryMan) {
		this.deliveryMan = deliveryMan;
	}

	public String getConsignee() {
		return consignee;
	}

	public void setConsignee(String consignee) {
		this.consignee = consignee;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getIsUpdate() {
		return isUpdate;
	}

	public void setIsUpdate(String isUpdate) {
		this.isUpdate = isUpdate;
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public Uploadable filter(Map<String, List<Uploadable>> map, Set<Uploadable> set, int num) throws Exception {
		/**容纳错误消息的list*/
 		List<Uploadable> mlist = new ArrayList<Uploadable>(Constant.SMALL_CAPACITY);
 		/**容纳正确的，最终用于保存到数据库的数据**/
 		List<Uploadable> list = new ArrayList<Uploadable>(Constant.SMALL_CAPACITY);
 	    
 		/***
 		 * 过滤掉所有的空格
 		 */
 				
 		String openid = StringUtil.trimAll(this.getOpenid());  
 		String prizeName = StringUtil.trimAll(this.getPrizeName()); 
 		String deliveryTime = StringUtil.trimAll(this.getDeliveryTime());      
 		String deliveryStatus = StringUtil.trimAll(this.getDeliveryStatus());    
 		String deliveryMan = StringUtil.trimAll(this.getDeliveryMan());   
 		String consignee = StringUtil.trimAll(this.getConsignee());      
 		String address = StringUtil.trimAll(this.getAddress());    
 		String id = StringUtil.trimAll(this.getId()); 
 		String flag = StringUtil.trimAll(this.getFlag()); 
 		/**
 	     * 判断是否导入的模板是正确的模板
 	     */
 	    if(num == 1) {
 	    		   if(!CollectionConstant.prize_mb.get(0).contains(prizeName)    
 	    			||!CollectionConstant.prize_mb.get(1).contains(deliveryTime)      
 	    			||!CollectionConstant.prize_mb.get(2).contains(deliveryStatus)      
 	    			||!CollectionConstant.prize_mb.get(3).contains(deliveryMan)       
 	    			||!CollectionConstant.prize_mb.get(4).contains(consignee)      
 	    			||!CollectionConstant.prize_mb.get(5).contains(address) 
 	    			||!CollectionConstant.prize_mb.get(6).contains(flag) 
 	    			||!CollectionConstant.prize_mb.get(7).contains(openid)   
 		    		||!CollectionConstant.prize_mb.get(8).contains(isUpdate) 
 		    		||!CollectionConstant.prize_mb.get(9).contains(id)  
 		    		
 	    			) {
 	    		MsgInfo msg = new MsgInfo(Constant.ERROR_MB,Constant.ERROR_MB,Constant.ERROR_MB,Constant.ERROR_NUM+num);
 				mlist.add(msg);
 				map.put("stop", mlist);
 		    	return null;
 		    }
 	    } else {
 	    	/***
 			 * 获取项目上下文的共享数据
 			 */
 			ServletContext servletContext = ServletContextUtils.getServletContext();
 			
 	    	/***
 		     * 数据合格性校验
 		     */
 		/*	if(!CollectionConstant.types.contains(type)) {
 				MsgInfo msg = new MsgInfo(type,"用户类型",CollectionConstant.types.toString(),Constant.ERROR_NUM+num);
 				mlist.add(msg);
 			}
 			
 			if(!CollectionConstant.cudFlags.contains(isUpdate)) {
 				MsgInfo msg = new MsgInfo(isUpdate,"修订标识",CollectionConstant.cudFlags.toString(),Constant.ERROR_NUM+num);
 				mlist.add(msg);
 			}*/
 			
 			/***
 			 * 返回处理后的结果数据
 			 */
 			if(!mlist.isEmpty()) {
 				map.put("fail"+num, mlist);
 			} 
 			/***把验证通过的合格数据返回*/
 			this.setAll( openid,  prizeName,  deliveryTime,  deliveryStatus,  deliveryMan,
 					 consignee,  address,  isUpdate ,id,flag);
 			set.add(this);
 			return this;
 	    }
	    return null;
	}

	@Override
	public String flag() throws Exception {
		return this.isUpdate;
	}

	@Override
	public String toString() {
		return "PrizeDTO [prizeName=" + prizeName + ", deliveryTime=" + deliveryTime + ", deliveryStatus="
				+ deliveryStatus + ", deliveryMan=" + deliveryMan + ", consignee=" + consignee + ", address=" + address
				+ ", flag=" + flag + ", isUpdate=" + isUpdate + ", id=" + id + ", openid=" + openid + "]";
	}

	public void setAll(String openid, String prizeName, String deliveryTime, String deliveryStatus, String deliveryMan,
			String consignee, String address, String isUpdate,String id,String flag) {
		this.openid = openid;
		this.prizeName = prizeName;
		this.deliveryTime = deliveryTime;
		this.deliveryStatus = deliveryStatus;
		this.deliveryMan = deliveryMan;
		this.consignee = consignee;
		this.address = address;
		this.isUpdate = isUpdate;
		this.id = id;
		this.flag = flag;
	}

	public PrizeDTO(String prizeName, String deliveryTime, String deliveryStatus, String deliveryMan, String consignee,
			String address, String flag, String isUpdate, String id, String openid) {
		super();
		this.prizeName = prizeName;
		this.deliveryTime = deliveryTime;
		this.deliveryStatus = deliveryStatus;
		this.deliveryMan = deliveryMan;
		this.consignee = consignee;
		this.address = address;
		this.flag = flag;
		this.isUpdate = isUpdate;
		this.id = id;
		this.openid = openid;
	}

	public PrizeDTO() {
		super();
	}

	
}